var t = getApp();

Page({
    data: {
        active: 0,
        current: 0,
        saleboxShow: !1,
        money: "",
        page: 1
    },
    onLoad: function(t) {
        wx.setNavigationBarTitle({
            title: "直播授权码"
        });
    },
    init: function() {
        this.setData({
            page: 1,
            last_page: 1,
            current: 0,
            saleboxShow: !1,
            info: []
        });
    },
    changeActive: function(t) {
        this.setData({
            info: [],
            active: t.detail.index
        }), this.init(), this.getdata();
    },
    swiperChange: function(t) {
        this.setData({
            current: t.detail.current
        });
    },
    tapSele: function() {
        this.setData({
            saleboxShow: !0,
            money: ""
        });
    },
    moneyInp: function(t) {
        console.log(t), this.setData({
            money: t.detail
        });
    },
    goDetail: function() {
        wx.navigateTo({
            url: "/packageH/liveAuthorization/liveAuthorization_detail/liveAuthorization_detail"
        });
    },
    saleClose: function() {
        this.setData({
            saleboxShow: !1
        });
    },
    sureBtnTap: function() {
        var a = this.data.money;
        if (console.log(this.data.info, this.data.current), 0 != this.data.info[this.data.current].code_num) {
            var e = this.data.info[this.data.current].id, o = this.data.info[this.data.current].level_id;
            t._isTextEmpty(a) ? wx.showToast({
                title: "请输入出售价格",
                icon: "none",
                duration: 1e3
            }) : this.sendLogs(e, o);
        } else wx.showToast({
            title: "授权码数量不足",
            icon: "none",
            duration: 1e3
        });
    },
    tapCode: function(t) {
        var a = this.data.info[this.data.current].level_id;
        wx.navigateTo({
            url: "/packageH/liveAuthorization/liveAuthorization_collection/liveAuthorization_collection?id=" + a
        });
    },
    onReady: function() {},
    onShow: function() {
        this.init(), this.getdata();
    },
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {
        if ("0" == this.data.active) {
            if (this.data.current_page >= this.data.last_page) return;
            var t = this.data.page + 1;
            this.setData({
                page: t
            }), this.getMore();
        }
    },
    onShareAppMessage: function() {},
    getdata: function() {
        var a, e = this;
        1 == e.data.active ? a = t.getNetAddresss("plugin.room.frontend.code.salabilityCode") : 0 == e.data.active && (a = t.getNetAddresss("plugin.room.frontend.code.purchasedCode")), 
        t._getNetWork({
            url: a,
            success: function(t) {
                var a = t.data;
                1 == a.result ? "1" == e.data.active ? e.setData({
                    info: a.data
                }) : "0" == e.data.active && e.setData({
                    info: a.data.data,
                    current_page: a.data.current_page,
                    last_page: a.data.last_page
                }) : wx.showToast({
                    icon: "none",
                    title: a.msg,
                    duration: 1500
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    getMore: function() {
        var a = this, e = t.getNetAddresss("plugin.room.frontend.code.purchasedCode");
        t._getNetWork({
            url: e,
            data: {
                page: a.data.page
            },
            success: function(t) {
                var e = t.data;
                1 == e.result ? a.setData({
                    info: a.data.info.concat(e.data.data),
                    current_page: e.data.current_page,
                    last_page: e.data.last_page
                }) : wx.showToast({
                    icon: "none",
                    title: e.msg,
                    duration: 1500
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    sendLogs: function(a, e) {
        var o = this, n = a, i = e, s = t.getNetAddresss("plugin.room.frontend.code.generatePoster");
        t._getNetWork({
            url: s,
            data: {
                id: n,
                money: o.data.money
            },
            success: function(t) {
                console.log(t);
                var a = t.data;
                1 === a.result ? wx.showToast({
                    title: "出售成功",
                    icon: "none",
                    duration: 1500,
                    success: function(t) {
                        console.log(t), setTimeout(function() {
                            o.setData({
                                saleboxShow: !1
                            }), wx.navigateTo({
                                url: "/packageH/liveAuthorization/liveAuthorization_collection/liveAuthorization_collection?id=" + i
                            });
                        }, 1500);
                    }
                }) : wx.showToast({
                    title: a.msg,
                    icon: "none",
                    duration: 1e3
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    tapActivate: function(a) {
        var e = this;
        if (1 == a.type) {
            var o = t.getNetAddresss("plugin.room.frontend.code.activationCode");
            t._getNetWork({
                url: o,
                data: {
                    id: a.id
                },
                success: function(t) {
                    e.getdata();
                },
                fail: function(t) {
                    console.log(t);
                }
            });
        }
    }
});